local skels = {}

local standard_card_names = {
  "slash", "thunder__slash", "fire__slash", "ice__slash", "jink", "peach", "ling__analeptic",
  "ling__lure_tiger", "ling__dismantlement", "ling__snatch", "duel", "ling__coll_horse",
  "ling__ex_nihilo", "ling__nullification", "ling__savage_assault", "archery_attack", "ling__amazing_grace",

  "iron_chain", "fire_attack", "ling__sincere_treat", "ling__drowning", "ling__stop_chasing", "ling__hide_capacities",
  "ling__divination", "ling__groom_and_drill",
}

for _, card_name in ipairs(standard_card_names) do
  local nameZh = Fk:translate(card_name, "zh_CN")
  if nameZh == card_name then
    nameZh = Fk:translate(string.split(card_name, "__")[2], "zh_CN")
  end
  local nameAbbr = nameZh
  local len = nameAbbr:len()
  if len == 1 then
    nameAbbr = "印"..nameAbbr
  elseif len > 2 then
    nameAbbr = string.sub(nameAbbr, 1, 6)
  end
  local skel_name = "lingling__moubian_"..card_name
  Fk:loadTranslationTable{
    [skel_name] = nameAbbr,
    [":"..skel_name] = "每轮限一次，你可以视为使用【"..nameZh.."】。",

    ["#"..skel_name] = "你可以视为使用【"..nameZh.."】",
  }

  local skel = fk.CreateSkill {
    name = skel_name,
  }
  skel:addEffect("viewas", {
    anim_type = "support",
    pattern = ".|.|.|.|"..card_name,
    card_filter = Util.FalseFunc,
    prompt = function (self, player, selected_cards, selected)
      return "#"..skel.name..":::"..skel.name:gsub("lingling__moubian_", "")
    end,
    view_as = function(self)
      local c = Fk:cloneCard(skel.name:gsub("lingling__moubian_", ""))
      c.skillName = skel.name
      return c
    end,
    enabled_at_play = function(self, player)
      return player:usedSkillTimes(skel.name, Player.HistoryRound) == 0
    end,
    enabled_at_response = function (self, player, response)
      return not response and player:usedSkillTimes(skel.name, Player.HistoryRound) == 0
    end,
  })

  skel:addLoseEffect(function (self, player)
    player:setSkillUseHistory(skel.name, 0, Player.HistoryRound)
  end)

  table.insert(skels, skel)
end

-- 20个备用
for i = 1, 20 do
  local skel_name = "lingling__moubian_"..i
  Fk:loadTranslationTable{
    [skel_name] = "印牌",
    [":"..skel_name] = "每轮限一次，你可以视为使用【？】。",
    [":"..skel_name.."_inner"] = "每轮限一次，你可以视为使用【{1}】。",
  }

  local skel = fk.CreateSkill {
    name = skel_name,
    dynamic_name = function (self, player, lang)
      if player:getMark(self.name) ~= 0 then
        return self.name.."_name:"..player:getMark(self.name)
      end
    end,
    dynamic_desc = function (self, player, lang)
      if player:getMark(self.name) ~= 0 then
        return self.name.."_inner:"..player:getMark(self.name)
      end
    end,
  }
  skel:addEffect("viewas", {
    pattern = ".",
    card_filter = Util.FalseFunc,
    prompt = function (self, player)
      local name = player:getMark(skel.name)
      if name ~= 0 then
        return "每轮限一次，你可以视为使用【"..Fk:translate(name).."】。"
      end
      return ""
    end,
    view_as = function(self, player)
      local name = player:getMark(skel.name)
      if name == 0 then return nil end
      local c = Fk:cloneCard(name)
      c.skillName = skel.name
      return c
    end,
    before_use = function (self, player, use)
      player:broadcastSkillInvoke("lingling__moubian")
    end,
    enabled_at_play = function(self, player)
      if player:usedSkillTimes(skel.name, Player.HistoryRound) == 0 then
        local name = player:getMark(skel.name)
        if name ~= 0 then
          local card = Fk:cloneCard(name)
          card.skillName = skel.name
          return player:canUse(card) and not player:prohibitUse(card)
        end
      end
    end,
    enabled_at_response = function (self, player, response)
      if not response and player:usedSkillTimes(skel.name, Player.HistoryRound) == 0 and Fk.currentResponsePattern then
        local name = player:getMark(skel.name)
        if name ~= 0 then
          return Exppattern:Parse(Fk.currentResponsePattern):matchExp(".|.|.|.|"..name)
        end
      end
    end,
  })

  skel:addLoseEffect(function (self, player)
    player:setSkillUseHistory(skel.name, 0, Player.HistoryRound)
    player.room:setPlayerMark(player, skel.name, 0)
  end)

  table.insert(skels, skel)
end

return skels
